package com.avecsys.quotemanager.service.system;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.avecsys.quotemanager.dao.system.SystemUserDAO;
import com.avecsys.quotemanager.dao.user.UserMasterDAO;
import com.avecsys.quotemanager.exception.BusinessException;
import com.avecsys.quotemanager.exception.DAOException;
import com.avecsys.quotemanager.pojos.CompanyMasterPojo;
import com.avecsys.quotemanager.pojos.SupplierMasterPojo;
import com.avecsys.quotemanager.pojos.SupplierUsersPojo;
import com.avecsys.quotemanager.pojos.SystemUsersPojo;
import com.avecsys.quotemanager.pojos.UserMasterPojo;
import com.avecsys.quotemanager.vo.SystemUserVO;

public class SystemUserServiceImpl implements SystemUserService {

	private UserMasterDAO userMasterDAO;
	
	private SystemUserDAO systemUserDAO;
	
	public SystemUserDAO getSystemUserDAO() {
		return systemUserDAO;
	}

	public void setSystemUserDAO(SystemUserDAO systemUserDAO) {
		this.systemUserDAO = systemUserDAO;
	}

	/**
	 * 
	 * @return List<SystemUsersPojo>
	 * @throws BusinessException
	 */
	@Override
	public List<SystemUsersPojo> getAllUsers()
			throws BusinessException {
		try {
			CompanyMasterPojo companyMasterPojo = getCompanyMasterForSystem();
			return userMasterDAO.findAllUsersForSystem(companyMasterPojo.getCompanyId());
		} catch (DAOException e) {
			throw new BusinessException(e);
		}
	}

	/**
	 * Method to get the company master information
	 * 
	 * @return CompanyMasterPojo instance
	 * @throws BusinessException
	 */
	@Override
	public CompanyMasterPojo getCompanyMasterForSystem() throws BusinessException {
		CompanyMasterPojo companyMasterPojo = new CompanyMasterPojo();
		try {
			companyMasterPojo = (CompanyMasterPojo) systemUserDAO.findSystemCompany(companyMasterPojo); 
		} catch (DAOException e) {
			throw new BusinessException(e);
		}
		return companyMasterPojo;
	}

	public UserMasterDAO getUserMasterDAO() {
		return userMasterDAO;
	}

	public void setUserMasterDAO(UserMasterDAO userMasterDAO) {
		this.userMasterDAO = userMasterDAO;
	}

	/**
	 * Method to verify the system email is not registered
	 * 
	 * @param SystemUserVO
	 * @param email
	 * @return boolean
	 * @throws BusinessException
	 */
	@Override
	public boolean isSystemUserEmailNotRegistered(SystemUserVO systemUserVO)
			throws BusinessException {
		return true;
	}

}
